import Vue from 'vue'
import Vuex from 'vuex'
import * as db from '../config/db.js'
Vue.use(Vuex)
// let userInfo = db.get('userInfo') || {}
// let userToken = db.get('userToken') || ''
const store = new Vuex.Store({
	state: {
		userInfo: {},
		userToken: ''
	},
	mutations: {
		saveUserTokenAction(state, userToken) {
			state.userToken = userToken;
			db.set('userToken', state.userToken)
		},
		setUserInfoMutations(state, userinfo) {
			state.userInfo = userinfo;
			db.set('userInfo', state.userInfo)
		}
	},
	actions: {
		saveUserTokenAction(state, userToken) {
			state.commit('saveUserTokenAction', userToken)
		},
		setUserInfoAction(state, userinfo) {
			state.commit('setUserInfoMutations', userinfo)
		}
	},
	getters: {
		getUserInfos(state) {
			return state.userInfo;
		},
		getisLogin(state) {
			if (JSON.stringify(state.userInfo) == "{}") {
				return false;
			} else {
				return true;
			}
		}
	}
})

export default store
